package logicGame.States;

import java.io.Serializable;
import logicGame.Cards.AndCard;
import logicGame.Cards.Card;
import logicGame.Cards.OrCard;
import logicGame.Game;

public class BuyCard extends StateAdapter implements Serializable {

    public BuyCard(Game g) {
        super(g);
    }

    @Override
    public State buy(int n) {

        if (getGame().getActivePlayer().checkCash(n)) {
            getGame().getActivePlayer().buyCardP(getGame().getAllBoardDeck().get(n));
            getGame().getAllBoardDeck().remove(n);
            getGame().getActivePlayer().actualizeResources();
            getGame().initializeBoardDeck();

            Card c = getGame().getActivePlayer().getLastCard();

            if (c instanceof OrCard) {
                return new Or(getGame());
            } else if (c instanceof AndCard) {
                return new And(getGame());
            } else {
                return new PickPlace(getGame());
            }

        } else {
            return this;
        }

    }
    
    @Override
    public State proxPlayer(){
        return this;
        
    }

}
